package com.jiayang.hhotel.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.Constant;

import cn.droidlover.xdroidmvp.mvp.XActivity;

/**
 * Created by Administrator on 2017/6/6 0006.
 * 统计分析列表页面
 */

public class StatisticsAnalysisListActivity extends XActivity {

    private ListView lv;
    private String[] list;
    private Integer[] imgRes;//背景图

    @Override
    public void initData(Bundle savedInstanceState) {
        initTitle(this,true,getString(R.string.staticstical_analysis),R.color.orange_color,null,null);
        lv = (ListView) findViewById(R.id.lv);
        list = getResources().getStringArray(R.array.statistics_analysis_list);
        imgRes = new Integer[]{R.drawable.style1,R.drawable.style2,R.drawable.style3,R.drawable.style4,R.drawable.style5,R.drawable.style1,R.drawable.style2,R.drawable.style3,R.drawable.style4,R.drawable.style5,R.drawable.style1};
        lv.setAdapter(new ListAdapter());
    }

    @Override
    public int getLayoutId() {
        return R.layout.layout_statistics_analysis_list;
    }

    @Override
    public Object newP() {
        return null;
    }

    class ListAdapter extends BaseAdapter{

        private Intent intent;
        @Override
        public int getCount() {
            return list.length;
        }

        @Override
        public Object getItem(int position) {
            return list[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if(convertView==null){
                convertView = LayoutInflater.from(StatisticsAnalysisListActivity.this).inflate(R.layout.statistics_analysis_list_item,null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            }
            holder = (ViewHolder) convertView.getTag();
            holder.content.setText(list[position]);
            holder.click.setBackgroundResource(imgRes[position]);
            holder.click.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(intent == null){
                        intent = new Intent(StatisticsAnalysisListActivity.this,StatisticalActivity.class);
                    }
                    intent.putExtra(Constant.INTENT_PROJECT_KEY,position + 1);
                    startActivity(intent);
                }
            });
            return convertView;
        }

        class ViewHolder {
            RelativeLayout click;
            TextView content;

            public ViewHolder(View item){
                click = (RelativeLayout) item.findViewById(R.id.rl);
                content = (TextView) item.findViewById(R.id.tv_content);
            }
        }
    }
}
